Make the progress bar speed variable
authorMatthias Clasen <mclasen@redhat.com>
Sun, 10 Nov 2013 06:15:59 +0000 (01:15 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 10 Nov 2013 06:15:59 +0000 (01:15 -0500)
Arrange for the scales to control the speed of the activity
mode progress bar in gtk3-widget-factory. This will be useful
in demonstrating smoother progress bar animation in the future.

demos/widget-factory/widget-factory.c

index 20ab75093f315d1e7f6b272cd67143aac345e552..da830e2c158344cc32974db4b0c2f55b0c41bce2 100644 (file)
@@ -129,11 +129,27 @@ dismiss (GtkWidget *button)
   gtk_revealer_set_reveal_child (GTK_REVEALER (w), FALSE);
 }
 
+static gint pulse_time = 250;
+
+static void
+update_pulse_time (GtkAdjustment *adjustment)
+{
+  gdouble value;
+
+  value = gtk_adjustment_get_value (adjustment);
+
+  /* vary between 50 and 450 */
+  pulse_time = 50 + 4 * value;
+}
+
 static gboolean
 pulse_it (GtkWidget *widget)
 {
   gtk_progress_bar_pulse (GTK_PROGRESS_BAR (widget));
-  return TRUE;
+
+  g_timeout_add (pulse_time, pulse_it, widget);
+  
+  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -172,6 +188,10 @@ activate (GApplication *app)
                                    win_entries, G_N_ELEMENTS (win_entries),
                                    window);
 
+  g_signal_connect (gtk_builder_get_object (builder, "adjustment1"),
+                    "value-changed",
+                    G_CALLBACK (update_pulse_time), NULL);
+
   widget = (GtkWidget *)gtk_builder_get_object (builder, "progressbar3");
   g_timeout_add (250, (GSourceFunc)pulse_it, widget);